/*
 * @Descripttion: 
 * @version: 
 * @Author: Lk
 * @Date: 2023-06-26 14:18:21
 * @LastEditors: Lk
 * @LastEditTime: 2023-07-03 15:33:33
 */
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index' + location.search,
                    add_url: 'order/order/add',
                    // edit_url: 'order/order/edit',
                    // del_url: 'order/order/del',
                    multi_url: 'order/order/multi',
                    import_url: 'order/order/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') ,operate: false },
                        { field: 'sn', title: __('Sn'), operate: 'LIKE' },
                        { field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE' },
                        { field: 'total_money', title: __('Total_money'), operate: 'BETWEEN',operate: false },
                        { field: 'point', title: __('Point') ,operate: false},
                        { field: 'point_deduction', title: __('Point_deduction'),operate: false },
                        { field: 'vip_deduction', title: __('Vip_deduction'),operate: false },
                        { field: 'pay_money', title: __('Pay_money'),operate: false},
                        { field: 'num', title: __('Num') ,operate: false},
                        { field: 'type', title: __('Type'), searchList: Config.type_list, formatter: Table.api.formatter.flag },
                        { field: 'pay_type', title: __('Pay_type'), searchList: { "1": __('Pay_type 1') }, formatter: Table.api.formatter.normal ,operate: false},
                        { field: 'remark', title: __('Remark'), operate: 'LIKE' },
                        { field: 'consignee', title: __('Consignee'), operate: 'LIKE' },
                        { field: 'phone', title: __('Phone'), operate: 'LIKE' },
                        { field: 'address', title: __('Address'), operate: 'LIKE' },
                        { field: 'enter.name', title: __('接单人'), operate: 'LIKE' },
                        { field: 'enter.phone', title: __('接单手机号'), operate: 'LIKE' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'paytime', title: __('Paytime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'servertime', title: __('Servertime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'canceltime', title: __('Canceltime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'taketime', title: __('Taketime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'status', title: __('Status'), searchList: { "0": __('Status 0'), "10": __('Status 10'), "20": __('Status 20'), "30": __('Status 30'), "40": __('Status 40'), "-1": __('Status -1') }, formatter: Table.api.formatter.status },
                        { field: 'complain', title: __('投诉状态'), searchList: { "0": __('未投诉'), "1": __('被投诉')}, formatter: Table.api.formatter.status },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'select',
                                    title: '查看商品',
                                    text: '查看商品',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/goods/index',//接口地址 控制器名/方法名
                                },
                                {
                                    name: 'send',
                                    title: '派单',
                                    text: '派单',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'order/order/send',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.status == '10') {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }

                                    },
                                },
                                {
                                    name: 'complain',
                                    title: '投诉',
                                    text: '投诉',
                                    classname: 'btn btn-primary btn-xs btn-view btn-ajax',
                                    url: 'order/order/complain',//接口地址 控制器名/方法名
                                    confirm: function (res) {
                                        if (res.complain) {
                                            return '是否确认投诉？';
                                        } else {
                                            return '是否取消投诉？';
                                        }
                                    },
                                    refresh: true,
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.employee_id > 0) {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        send: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
